package com.itany.shop.tran.impl;


import com.itany.shop.exception.ServiceException;
import com.itany.shop.tran.TransactionManager;
import com.itany.shop.util.MyBatisUtil;


import java.sql.SQLException;

/**
 * @author Miss Chen
 * @version 1.0
 * @date 2024年08月14日15:07
 */
public class TransactionManagerImpl implements TransactionManager {
    @Override
    public void begin() {
        MyBatisUtil.getSession();
    }

    @Override
    public void commit() {
        try {
            MyBatisUtil.getSession().commit();
            MyBatisUtil.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException("事务提交出错");
        }
    }

    @Override
    public void rollback() {
        try {
            MyBatisUtil.getSession().rollback();
            MyBatisUtil.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException("事务回滚出错");
        }

    }
}
